package com.xxq.gulimall.product.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.xxq.common.valid.AddGroup;
import com.xxq.common.valid.ChangeCategorySort;
import com.xxq.common.valid.UpdateGroup;
import lombok.Data;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.*;

/**
 * 商品三级分类
 * 
 * @author xxq
 * @email 1607903138@qq.com
 * @date 2022-04-28 20:20:13
 */
@Data
@TableName("pms_category")
public class CategoryEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 分类id
	 */
	@TableId
	@Null(message = "新增数据不能携带catId", groups = {AddGroup.class})
	@NotNull(message = "更新数据必须携带catId", groups = {UpdateGroup.class, ChangeCategorySort.class})
	//@Pattern(regexp = "^[1-9]\\d*$", message = "cid必须是正整数", groups = { UpdateGroup.class})
	private Long catId;
	/**
	 * 分类名称
	 */
	@NotEmpty(message = "菜单名称不能为空", groups = {AddGroup.class})
	private String name;
	/**
	 * 父分类id
	 */
	@NotNull(message = "更新父子排序以及顺序时，parentCid必须有效", groups = {AddGroup.class, UpdateGroup.class, ChangeCategorySort.class})
	private Long parentCid;
	/**
	 * 层级
	 */
	//@Pattern(regexp = "^[1-3]*$", message = "catLevel必须是1-3的数字", groups = {AddGroup.class, UpdateGroup.class, ChangeCategorySort.class})
	@Range(min = 1, max = 3, message = "catLevel只能是1到3的整数", groups = {AddGroup.class, UpdateGroup.class, ChangeCategorySort.class})
	@NotNull(message = "catLevel不能为空", groups = {AddGroup.class, ChangeCategorySort.class})
	private Integer catLevel;
	/**
	 * 是否显示[0-不显示，1显示]
	 */
	@TableLogic(value = "1", delval = "0")
	@NotNull(message = "showStatus不能为空", groups = {AddGroup.class})
	@Range(min = 0, max = 1, message = "showStatus只能为0或1", groups = {AddGroup.class, UpdateGroup.class, ChangeCategorySort.class})
	private Integer showStatus;
	/**
	 * 排序
	 */
	//@Pattern(regexp = "^[0-9]+$", message = "catLevel必须是非负整数", groups = {AddGroup.class, UpdateGroup.class, ChangeCategorySort.class})
	@Min(value = 0, message = "sort值最小为0", groups = {AddGroup.class, UpdateGroup.class, ChangeCategorySort.class})
	@NotNull(message = "sort值不能为空", groups = {AddGroup.class, ChangeCategorySort.class})
	private Integer sort;
	/**
	 * 图标地址
	 */
	private String icon;
	/**
	 * 计量单位
	 */
	private String productUnit;
	/**
	 * 商品数量
	 */
	private Integer productCount;

	/*
	  子分类
	 */
	@TableField(exist = false) //表示不在数据库表中
	private List<CategoryEntity> children = new ArrayList<>();

}
